import BigNumber from "bignumber.js"
import moment, { MomentInput } from "moment";

export const formatAmount = (value: number, d = 6) => {
  return BigNumber(value).dp(d, BigNumber.ROUND_DOWN).toFixed()
}

export const formatEvmAddress = (address: string) => {
  if(!address) return "";
  return `${address.substring(0,6)}...${address.substring(address.length - 4)}`
}

export const formatThousandsAmount = (value: BigNumber.Value, d = 6) => {
  return BigNumber(value).dp(d, BigNumber.ROUND_DOWN).toFormat()
}

export const momentFromNow = (stopTime: MomentInput) => {
  const diff = moment(stopTime).diff(moment(), 'minutes');
  const hour = Math.ceil(diff / 60);
  const minutes = Math.ceil(diff % 60);

  return `${hour}h ${minutes}m`
}

export const formatShotAmount = (amount: number = 0) => {
  if(amount >= 1000000000) return `${formatAmount(amount / 1000000000, 3)} B`;
  if(amount >= 1000000) return `${formatAmount(amount / 1000000), 3} M`
  if(amount >= 1000) return `${formatAmount(amount / 1000, 3)} K`;
  return `${formatAmount(amount, 3)}`
}